package com.beinhospital_sw21_h2_05.beinhospitalsw21h205.service.impl;

import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.entity.Department;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.mapper.DepartmentMapper;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.service.DepartmentService;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.utils.PageBean;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentImpl implements DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    /**
     * 分页查询科室列表。
     *
     * @param page           页码
     * @param pageSize       每页记录数
     * @param departmentName 用于过滤的科室名称（可为null）
     * @return 包含分页科室列表的PageBean
     */
    @Override
    public PageBean page(Integer page, Integer pageSize, String departmentName) {
        PageHelper.startPage(page, pageSize);
        List<Department> departmentList = departmentMapper.list(departmentName);
        Page<Department> p = (Page<Department>) departmentList;
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }

    /**
     * 根据科室ID删除科室信息。
     *
     * @param departmentID 科室ID
     */
    @Override
    public void delete(Integer departmentID) {
        departmentMapper.delete(departmentID);
    }

    /**
     * 新增科室信息。
     *
     * @param department 待新增的科室对象
     */
    @Override
    public void add(Department department) {
        departmentMapper.insert(department);
    }

    /**
     * 编辑科室信息。
     *
     * @param department 待编辑的科室对象
     */
    @Override
    public void update(Department department) {
        departmentMapper.update(department);
    }
}
